﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using PowerCreator.LMS.Web.Action;
using PowerCreator.LMS.Web.Config;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;

public partial class sysadmin_RoleManager_ActionManage : PowerCreator.LMS.Web.Base.BasePage
{
    PowerCreator.LMS.Web.Action.Action opAction = new PowerCreator.LMS.Web.Action.Action();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
        }
    }
    /// <summary>
    /// 初始化界面信息，多语言项
    /// </summary>
    protected override void InitPage()
    {
        //lbl_RoleName.Text = GetLanageValueByKey("lbl_ActionManage_RoleName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_RoleDesc.Text = GetLanageValueByKey("lbl_ActionManage_RoleDesc", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_InfoTitle.Text = GetLanageValueByKey("lbl_ActionManage_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_AddAdminGroup.Text = GetLanageValueByKey("btn_ActionManage_AddAdminGroup", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Back.Text = GetLanageValueByKey("btn_ActionManage_Back", PowerCreator.LMS.Language.LanagetItemType.Page);
    }
    private bool CheckPageData()
    {
        if (string.IsNullOrEmpty(txt_RoleName.Text))
        {
            lbl_msg_RoleName.Text = GetLanageValueByKey("lbl_msg_RoleName_minlength", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        if (txt_RoleName.Text.Length > 20)
        {
            lbl_msg_RoleName.Text = GetLanageValueByKey("lbl_msg_RoleName_maxlength", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        if (txt_RoleDesc.Text.Length > 200)
        {
            lbl_msg_RoleDesc.Text = GetLanageValueByKey("lbl_msg_RoleDesc_maxlength", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        string search = string.Format(" RoleName = '{0}'", txt_RoleName.Text);

        if (opAction.QueryRoleCount(search) != 0)
        {
            lbl_msg_RoleName.Text = GetLanageValueByKey("lbl_ActionManage_aspx_RoleName", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }

        return true;
    }
    protected void btn_AddAdminGroup_Click(object sender, EventArgs e)
    {
        PowerCreator.LMS.Action.Entity.VOTRole vo = new PowerCreator.LMS.Action.Entity.VOTRole();
        vo.FKRoleCreatorId = GetLoginEntity.UserID;
        vo.RoleCreateTime = DateTime.Now;
        vo.RoleCreatorName = GetLoginEntity.UserName;
        vo.RoleDescription = txt_RoleDesc.Text;
        vo.RoleName = txt_RoleName.Text;
        vo.State = 1;

        if (!CheckPageData()) return;
        if (opAction.AddRole(vo))
        {
            string url = "ManagerRole.aspx";
            Script.RedirectURL(url);
        }
        else
        {
            lbl_msg_RoleName.Text = GetLanageValueByKey("lbl_msg_managerrole_add", PowerCreator.LMS.Language.LanagetItemType.MSG);
        }
    }
    protected void btn_back_Click(object sender, EventArgs e)
    {
        string url = "ManagerRole.aspx";
        Script.RedirectURL(url);
    }
}
